package com.oig.sys.workflow.flow.module;

import cn.hutool.core.date.LocalDateTimeUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 飞书通用表单传值结构
 */
@Getter
@Setter
@ToString
public class FeishuFormModule {
    @Schema(description = "表单自定义字段名")
    private String id;
    @Schema(description = "表单类型")
    private String type;
    @Schema(description = "值")
    private Object value;


    @Getter
    @Setter
    @ToString
    public static class DateInterval{
        @Schema(description = "日期段表单控件的起始日期时间")
        private String start;
        @Schema(description = "日期段表单控件的截止日期时间")
        private String end;
        @Schema(description = "日期段的日期差")
        private float interval;

        public float getInterval(){
            if (StringUtils.isBlank(start)||StringUtils.isBlank(end)) return interval;
            LocalDateTime startTime = LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss+08:00")) ;
            LocalDateTime endTime = LocalDateTime.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss+08:00")) ;
            return LocalDateTimeUtil.betweenPeriod(startTime.toLocalDate(), endTime.toLocalDate()).getDays();
        }
    }

    @Getter
    @Setter
    @ToString
    public static class TelephoneV{
        @Schema(description = "电话所属国家，默认中国")
        private String countryCode="+86";
        @Schema(description = "号码")
        private String nationalNumber;
    }



}
